package com.shigu.activity.action;

import com.shigu.MallResponse;
import com.shigu.PageResponse;
import com.shigu.activity.api.ActivityService;
import com.shigu.activity.bo.ActivityItemRequest;
import com.shigu.activity.vo.ActivityListVo;
import com.shigu.exceptions.AdminException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("adminjson")
public class ActivityAdminController {

    @Resource(name = "activityServiceImpl")
    ActivityService activityService;

    @RequestMapping("setActivityItem")
    @ResponseBody
    public MallResponse setActivityItem(ActivityItemRequest request) throws AdminException {
        activityService.setActivityItem(StringUtils.isBlank(request.getaId()) ? null : Long.valueOf(request.getaId()),
                request.getTitle(), request.getSmallImgSrc(),request.getBgImgSrc(), Integer.valueOf(request.getType()));
        return new MallResponse().success();
    }

    @RequestMapping("getActivityList")
    @ResponseBody
    public PageResponse<ActivityListVo> getActivityList() {
        return activityService.getActivityList().success();
    }

    @RequestMapping("deleteActivityItem")
    @ResponseBody
    public MallResponse deleteActivityItem(String aId) throws AdminException {
        activityService.deleteActivityItem(Long.valueOf(aId));
        return new MallResponse().success();
    }
}
